// 引入 ECharts 主模块
var echarts = require('echarts/lib/echarts')
// 引入柱状图
require('echarts/lib/chart/pie')
// 引入提示框和标题组件
require('echarts/lib/component/tooltip')
require('echarts/lib/component/title')
require('echarts/lib/component/legend')
require('echarts/lib/component/grid')
export default class EchartsConfig {
  private myChart: any
  private option = {
    tooltip: {
      trigger: 'item',
      formatter: '{b}: {c} ({d}%)'
    },
    legend: {
      show: false,
      orient: 'vertical',
      x: 'left',
      data: []
    },
    series: [
      {
        name: '默认底盘',
        type: 'pie',
        radius: ['0%', '100%'],
        avoidLabelOverlap: false,
        silent: true,
        label: {
          normal: {
            show: false
          },
          emphasis: {
            show: false
          }
        },
        itemStyle: {
          color: 'rgba(11, 31, 57, 0.8)'
        },
        labelLine: {
          normal: {
            show: false
          }
        },
        data: [{ value: 1, name: '默认底盘' }]
      },
      {
        name: '',
        type: 'pie',
        radius: ['60%', '80%'],
        avoidLabelOverlap: false,
        label: {
          normal: {
            show: false,
            position: 'center'
          },
          emphasis: {
            show: false
          }
        },
        labelLine: {
          normal: {
            show: false
          }
        },
        data: []
      }
    ]
  }
  constructor(domId: string) {
    this.myChart = echarts.init(document.getElementById(domId))
  }
  public setOption(data: any[]) {
    this.option.series[1].data = data
    this.myChart && this.myChart.setOption(this.option)
  }
}
